package 周赛;

import java.util.Arrays;

public class 分配给商店的最多商品的最小值 {

    //求最大值中的最小值问题，使用二分搜索
    public int minimizedMaximum(int n, int[] quantities) {
        int l = 0 , r=(int)1e5;
        while (l < r){
            int mid = (l+r)/2;
            int cnt = 0;
            for (int quantity : quantities) {
                cnt +=  Math.ceil(quantity/mid);  //向上取整
            }
            if (cnt <= n){
                r = mid;
            }
            else
                l = mid+1;
        }
        return r;
    }
}
